'use strict';

describe('单元测试: services.customActivity.summary.health.summaryHealthService', function () {
  beforeEach(angular.mock.module('services.customActivity.summary'));

  var $httpBackend, summaryHealthService;

  beforeEach(inject(function ($injector) {
    $httpBackend = $injector.get('$httpBackend');
    summaryHealthService = $injector.get('summaryHealthService');
  }));

  it('queryHealthInfo(),后端响应数据后,赋值给healthInfo', function () {
    $httpBackend.whenPOST('/sas/customActivity/summary/health/query').respond(
      {
        state: '10000',                   //操作是否成功，10000代表成功
        message: '',     //错误信息 成功返回空字符串，失败则返回错误信息
        data: {
          max: 99.99,
          min: 99.99,
          avg: 99.99
        }
      }
    );
    summaryHealthService.queryHealthInfo();
    $httpBackend.flush();
    expect(summaryHealthService.healthInfo).toEqual({
      max: 99.99,
      min: 99.99,
      avg: 99.99
    });
  });

  it('queryHealthInfo(),后端错误时,数据为空', function () {
    $httpBackend.whenPOST('/sas/customActivity/summary/health/query').respond(
      {
        state: '10000',                   //操作是否成功，10000代表成功
        message: '',     //错误信息 成功返回空字符串，失败则返回错误信息
        data: {}
      }
    );
    summaryHealthService.queryHealthInfo();
    $httpBackend.flush();
    expect(summaryHealthService.healthInfo).toEqual({});
  });
});